package cpa.prowon.gui.actions;

import java.io.File;

import org.eclipse.swt.widgets.DirectoryDialog;

import cpa.prowon.Application;
import cpa.prowon.gui.MainWindow;

/**
 * Exports images to the file system by simply copying the files
 * to the file system in the current viewed categorization and
 * taking the selected index category
 * @author Chris
 */
public class ExportAllToFolderAction extends PatchedAction {

	/**
	 * Constructor
	 * @param MainWindow The main window where the action is used
	 * @author Chris 
	 */
	public ExportAllToFolderAction(MainWindow w) {
		super(w);
	}

	/**
	 * Return the title key
	 * @return The title key
	 * @author Chris
	 */
	protected String getTitleKey() {
		return "menu_item_file_exportalltofolder";
	}

	/**
	 * Return the tooltip key
	 * @return The tootip key
	 * @author Chris
	 */
	protected String getTooltipKey() {
		return "menu_item_file_exportalltofolder_tooltip";
	}

	/**
	 * Return the image key
	 * @return The image key
	 * @author Chris
	 */
	protected String getImageKey() {
		return "";
	}

	/**
	 * Run the action
	 * @author Chris
	 */
	public void run() {

		// Prompt for the directory
		DirectoryDialog dialog = new DirectoryDialog (window.getShell());
		dialog.setMessage(Application.getInstance().getResourceBundle().getString("msg_selectfoldertoexportimages"));
		dialog.setText(Application.getInstance().getResourceBundle().getString("title_selectdirectory"));
		String result = dialog.open ();
		
		// Return if no directory was chosen
		if (result == null) return;

		// Export the images
		window.getCategoryPart().getRootIndexCategory().exportToFolder(new File(result));
		
	}

}
